package com.hare.system_server.serice.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hare.common.utils.PageUtils;
import com.hare.system_api.dto.SysDictDTO;
import com.hare.system_api.po.SysDictData;
import com.hare.system_api.vo.SysDictDataVO;
import com.hare.system_server.mapper.SysDictDataMapper;
import com.hare.system_server.serice.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: Hare
 * @description: 字典数据实现Service
 * @author: Hare
 * @create: 2022-11-30 21:02
 * @Version 6.0.1
 **/
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements SysDictDataService {


    @Autowired
    SysDictDataMapper sysDictDataMapper;


    /**
     * 根据名称，类型，状态查询字典数据信息(分页)
     *
     * @param dict 字典信息
     * @return
     */
    @Override
    public PageUtils<SysDictDataVO> pageDictDataInfo(SysDictDTO dict) {
        Page<SysDictDataVO> sysDictDataVOPage = sysDictDataMapper.pageDictDataInfo(new Page(dict.getPageIndex(), dict.getPageSize()), dict);
        if (ObjectUtil.isNotNull(sysDictDataVOPage.getRecords())) {
            return new PageUtils<>(sysDictDataVOPage.getRecords(), sysDictDataVOPage.getTotal(), sysDictDataVOPage.getSize(), sysDictDataVOPage.getCurrent());
        }
        return new PageUtils<>();
    }

    @Override
    public List<SysDictDataVO> selectDictDataById(String dictCode) {
        return sysDictDataMapper.selectDictDataById(dictCode);
    }
}
